<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SubjectContentService
 *
 * @author Administrator
 */
class SubjectContentService {

    function insert($sc) {
        $lastId = D('subject_content')->add($sc);

//        echo (D('subject_content')->getLastSql());
        return $lastId;
    }

    function update($sc) {
        $lastId = D('subject_content')->save($sc);

//        echo (D('subject_content')->getLastSql());
        return $lastId;
    }

    function countSubjectContentBySId($sId) {
        $scTable = D('subject_content');

        $where['subject_id'] = array('eq', $sId);

        return $scTable->where($where)->count();
    }

    /**
     * 专题下的具体内容
     * @param type $sId 专题Id
     * @param type $limit
     * @param type $field
     * @return type 
     */
    function listSubjectContentBySId($sId, $limit, $field='*') {
        $scTable = D('subject_content');

        $where['subject_id'] = array('eq', $sId);

        return $scTable->where($where)->field($field)->order('id asc')->limit($limit)->select();
    }

    function findSubjectById($id, $field='*') {
        $scTable = D('subject_content');

        return $scTable->field($field)->find($id);
    }

}

?>
